export const getTableOption = (type, safe) => {
  const columMap = {
    workshop: [
      {
        label: '车间编码',
        prop: 'objectCode',
        type: 'search',
        search: true,
        searchType: 'input',
        disabled: true,
        rules: [
          {
            required: true,
            message: '请选择车间编码',
            trigger: 'blur'
          }
        ],
        appendClick: () => {
          safe.openWorkshopCommonModal();
        }
      },
      {
        label: '车间名称',
        prop: 'objectName',
        search: true,
        disabled: true
      },
      {
        label: '标准UPH',
        prop: 'uph',
        type: 'number',
        rules: [{ required: true, trigger: 'blur', message: '请输入标准UPH' }]
      },
      {
        label: '',
        prop: 'continueUse',
        type: 'checkbox',
        hide: true,
        dicData: [
          {
            label: '该工厂内所有车间、所有产线都沿用该目标',
            value: 'CHECKBOX'
          }
        ]
      },
      {
        label: '更新人',
        prop: 'updateUserName',
        display: false
      },
      {
        label: '更新时间',
        prop: 'updateTime',
        display: false
      }
    ],
    product: [
      {
        label: '产品编码',
        prop: 'objectCode',
        type: 'search',
        search: true,
        searchType: 'input',
        appendClick: () => {
          safe.openPartCommonModal();
        }
      },
      {
        label: '产品名称',
        prop: 'objectName',
        disabled: true,
        search: true
      },
      {
        label: '产品规格',
        prop: 'partModel',
        search: true,
        disabled: true
      },
      {
        label: '标准UPH',
        prop: 'uph',
        type: 'number',
        rules: [{ required: true, trigger: 'blur', message: '请输入标准UPH' }]
      }
    ],
    line: [
      {
        label: '产线名称',
        prop: 'objectName',
        search: true,
        disabled: true
      },
      {
        label: '产线编码',
        prop: 'objectCode'
      },
      {
        label: '标准UPH',
        prop: 'uph',
        type: 'number',
        rules: [{ required: true, trigger: 'blur', message: '请输入标准UPH' }]
      },
      {
        label: '更新人',
        prop: 'updateUserName',
        display: false
      },
      {
        label: '更新时间',
        prop: 'updateTime',
        display: false
      }
    ]
  };
  return columMap[type];
};

export const detailOption = {
  height: 'calc(100vh - 350px)',
  calcHeight: 30,
  tip: false,
  searchShow: true,
  searchMenuSpan: 6,
  border: true,
  index: true,
  indexLabel: '序号',
  viewBtn: false,
  addBtn: false,
  editBtn: true,
  delBtn: true,
  cellBtn: true,
  addRowBtn: true,
  selection: true,
  dialogClickModal: false,
  menuWidth: 150,
  column: [
    {
      label: '工段',
      prop: 'sectionId',
      width: 150,
      cell: true,
      type: 'select',
      dicData: [],
      rules: [
        {
          required: true,
          message: '请选择工段',
          trigger: 'blur'
        }
      ]
    },
    {
      label: '标准UPH',
      prop: 'fpyGoal',
      type: 'number',
      cell: true,
      rules: [{ validator: validUph, trigger: 'submit' }]
    }
  ]
};

const validUph = (rule, value, callback) => {
  if (value != 0 && !value) {
    callback(new Error('请输入目标值'));
  } else {
    if (value <= 0) {
      callback(new Error('目标值要大于0'));
    } else if (value > 100) {
      callback(new Error('目标值要小于100'));
    } else {
      callback();
    }
  }
};

export const factoryConfigOption = {
  labelWidth: '130',
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '工厂UPH',
      prop: 'uph',
      type: 'number',
      row: true,
      span: 20,
      rules: [{ required: true, trigger: 'blur', message: '请输入工厂UPH' }]
    },
    {
      label: '',
      prop: 'continueUse',
      type: 'checkbox',
      row: true,
      span: 20,
      dicData: [
        {
          label: '该工厂内所有车间、所有产线都沿用该目标',
          value: 'CHECKBOX'
        }
      ]
    }
  ]
};
